<template>
  <div id="videoList">
    <el-input size="small" @keyup.enter.native="searchHandle" style="width: 300px" v-model="keywords"
              placeholder="搜索视频名称"></el-input>
    <el-button @click="searchHandle()" style="margin-left: 10px" type="primary" icon="el-icon-search" size="small">搜索
    </el-button>
    <div style="display: inline-block;margin-left: 20px;font-size:14px;">
      筛选：
      <el-radio v-model="hasAuth" label='0' @change="searchHandle">未审核</el-radio>
      <el-radio v-model="hasAuth" label='2' @change="searchHandle">未通过</el-radio>
    </div>
    <el-table
        height="536"
        :data="videoList"
        v-loading="loading"
        element-loading-text="拼命加载中"
        style="width: 99.5%">
      <el-table-column
          label="序号"
          align="center"
          type="index"
          :index="indexMethod">
      </el-table-column>
      <el-table-column
          label="视频封面"
          align="center"
          show-overflow-tooltip>
        <template slot-scope="scope">
          <el-image :src="scope.row.coverUrl" style="height:45px;width:60%;"></el-image>
        </template>
      </el-table-column>
      <el-table-column
          label="视频标题"
          prop="videoTitle"
          align="center"
          show-overflow-tooltip>
      </el-table-column>
      <el-table-column
          label="视频内容"
          prop="videoIntroduce"
          align="center"
          show-overflow-tooltip
      >
      </el-table-column>
      <el-table-column
          label="视频地址"
          prop="videoUrl"
          align="center"
          show-overflow-tooltip>
        <template slot-scope="scope">
          <el-link :href="scope.row.videoUrl" type="primary" :underline="false">链接</el-link>
        </template>
      </el-table-column>
      <el-table-column
          label="主讲人"
          align="center"
          prop="speaker"
          show-overflow-tooltip>
      </el-table-column>
      <el-table-column
          label="主办单位"
          prop="institutions"
          align="center"
          show-overflow-tooltip>
      </el-table-column>
      <el-table-column
          label="操作"
          align="center"
      >
          <template slot-scope="scope">
              <el-tooltip  v-show="hasAuth!='2'" class="item" effect="light" content="审核通过" placement="top">
                <el-button @click="aduit(scope.row.videoId,scope.row.videoTitle,'pass')" size="mini"
                           class="iconfont icon-shenhetongguo" type="success"></el-button>
              </el-tooltip>
              <el-tooltip  v-show="hasAuth!='2'" class="item" effect="light" content="审核不通过" placement="top">
                <el-button @click="aduit(scope.row.videoId,scope.row.videoTitle,'noPass')" size="mini"
                           class="iconfont icon-shenhebutongguo" type="danger"></el-button>
              </el-tooltip>
          </template>
      </el-table-column>
    </el-table>
    <el-pagination
        background
        layout="total,prev, pager, next"
        :total="total"
        align="center"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-size="pageSize"
        :hide-on-single-page="value"
        style="padding-top: 15px"
    >
    </el-pagination>
  </div>
</template>

<script>
import {auditVideo, getVideoList} from "@/network/admin";

export default {
  name: "VideoAudit",
  data() {
    return {
      videoList: [],
      video: {},
      loading: true,
      keywords: '',
      value: false,
      currentPage: 1,
      total: 1,
      pageSize: 6,
      detailInfoVisible: false,
      hasAuth: '0'
    }
  },

  created() {
    this.handleCurrentChange(this.currentPage);
  },
  methods: {
    handleCurrentChange(currentPage) {
      getVideoList(this.keywords, currentPage, this.pageSize, parseInt(this.hasAuth)).then(res => {
        this.loading = false;
        this.total = res.data.data.total;
        this.videoList = res.data.data.list;
        this.currentPage = currentPage;
      })
    },
    searchHandle() {
      this.currentPage = 1;
      this.handleCurrentChange(this.currentPage)
    },
    aduit(videoId, videoTitle, res) {
      auditVideo(videoId, res).then(res => {
        if (res.data.data == "pass") {
          this.$message.success(videoTitle + "审核通过");
        } else if (res.data.data == "noPass") {
          this.$message.warning(videoTitle + "审核不通过");
        }
        this.handleCurrentChange(this.currentPage);
      })
    },
    indexMethod(index) {
      return (this.currentPage - 1) * this.pageSize + 1 + index;
    },
    detailInfo(video) {
      this.detailInfoVisible = true;
      this.video = video;
    }

  }
}
</script>
<style scoped>
.demo-table-expand {
  font-size: 0;
}

.demo-table-expand label {
  min-width: 130px;
  height: 75px;
  color: #99a9bf;
}

.demo-table-expand .el-form-item {
  margin-left: 50px;
  margin-bottom: 0;
  width: 40%;
}

.el-form-item__content {
  height: 75px;
}
</style>